MPASM 03.20.02 Released          DEMO.ASM   2-20-2006  12:01:52         PAGE  1


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

                      00001         LIST   P=PIC16F877a
                      00002         #INCLUDE "P16F877A.INC"
                      00001         LIST
                      00002 ; P16F877A.INC  Standard Header File, Version 1.00    Microchip Technology, Inc.
                      00417         LIST
                      00003         ;errorlevel -302                ;suppress "not in bank 0" message
                      00004 
2007   3F32           00005         __CONFIG        _CP_OFF & _DEBUG_OFF & _LVP_OFF & _PWRTE_ON & _WDT_OFF & _BODEN_OFF & _HS_OSC
                      00006 
                      00007 ; '__CONFIG' directive is used to embed configuration data within .asm file.
                      00008 ; The labels following the directive are located in the respective .inc file.
                      00009 ; See respective data sheet for additional information on configuration word.
                      00010 
                      00011 ;Memory definition:
  00000020            00012 Ram             EQU     h'20'           ; Look datasheets gpr starts at file address 20h
  00000020            00013 WREG_TEMP       EQU     Ram+0           ;storage for WREG during interrupt
  00000021            00014 STATUS_TEMP     EQU     Ram+1           ;storage for STATUS during interrupt
  00000022            00015 PCLATH_TEMP     EQU     Ram+2           ;storage for PCLATH during interrupt
  00000023            00016 FSR_TEMP        EQU     Ram+3           ;storage for FSR during interrupt       
  00000030            00017 Timer_local     EQU     Ram+10
  00000031            00018 DataIN1         EQU     Ram+11
  00000032            00019 DataIN2         EQU     Ram+12
  00000033            00020 DutyCycle       EQU     Ram+13
                      00021 
                      00022 
0000                  00023                 ORG     0x0000          ;Reset vector
0000   2805           00024                 GOTO    Main
0001   0000           00025                 nop
0002   0000           00026                 nop             
0004                  00027                 ORG     0x0004          ;Interrupt vector
0004   2840           00028                 GOTO    Int
                      00029 
0005                  00030 Main            
                      00031                 Bank0
0005   1283               M                 bcf     STATUS,RP0
0006   1303               M                 bcf     STATUS,RP1
0007   2017           00032                 CALL    SetupSerial
0008   0188           00033                 CLRF    PORTD           ;All of portd low
0009   3000           00034                 MOVLW   B'00000000'
000A   009F           00035                 MOVWF   ADCON0
                      00036                 Bank1
000B   1683               M                 bsf     STATUS,RP0
000C   1303               M                 bcf     STATUS,RP1
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
000D   0188           00037                 CLRF    TRISD   
000E   3006           00038                 MOVLW   B'00000110'
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
000F   009F           00039                 MOVWF   ADCON1
0010   3007           00040                 MOVLW   0x07
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
0011   009C           00041                 MOVWF   CMCON   
                      00042                 Bank0   
0012   1283               M                 bcf     STATUS,RP0
MPASM 03.20.02 Released          DEMO.ASM   2-20-2006  12:01:52         PAGE  2


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

0013   1303               M                 bcf     STATUS,RP1
                      00043 
0014                  00044 Loop            
0014   1E0C           00045                 BTFSS   PIR1,TXIF       ;Check if transmitter busy      
0015   283C           00046                 GOTO    Loop1ms
0016   2814           00047                 GOTO    Loop    
                      00048 
0017                  00049 SetupSerial
                      00050                 Bank1                   ;Select bank 1
0017   1683               M                 bsf     STATUS,RP0
0018   1303               M                 bcf     STATUS,RP1
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
0019   1307           00051                 BCF     TRISC,6         ;Make RC6 - TX pin an output
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
001A   1787           00052                 BSF     TRISC,7         ;Make RC7 - RX pin an input
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
001B   1118           00053                 BCF     TXSTA,BRGH      ;Select low speed mode  
001C   300C           00054                 MOVLW   D'12'
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
001D   0099           00055                 MOVWF   SPBRG           ;Select baud rate 9600 in low speed     
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
001E   1218           00056                 BCF     TXSTA,SYNC      ;Select async mode      
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
001F   1698           00057                 BSF     TXSTA,TXEN      ;Enable Transmit
                      00058                 Bank0                   ;Select bank0
0020   1283               M                 bcf     STATUS,RP0
0021   1303               M                 bcf     STATUS,RP1
0022   3090           00059                 movlw   0x90            ;Enable serial port and reception
0023   0098           00060                 movwf   RCSTA
0024   30C0           00061                 movlw   0xc0            ;Enable global and peripheral ints
0025   008B           00062                 movwf   INTCON
                      00063                 Bank1                   ;Select bank1
0026   1683               M                 bsf     STATUS,RP0
0027   1303               M                 bcf     STATUS,RP1
0028   3020           00064                 movlw   0x20            ;(0x30 enable TX) and RX interrupts
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
0029   008C           00065                 movwf   PIE1
                      00066                 Bank0
002A   1283               M                 bcf     STATUS,RP0
002B   1303               M                 bcf     STATUS,RP1
002C   0008           00067                 return
                      00068 
002D                  00069 SetupPWM
002D   1683           00070                 BSF     STATUS,RP0      ; reg. Bank 0 (kijk blz 68 van datasheet voor meer informatie)
002E   30FF           00071                 MOVLW   H'ff'           ; 11111111
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
002F   0092           00072                 MOVWF   PR2             
0030   1283           00073                 BCF     STATUS,RP0      ; reg. Bank 0
0031   3000           00074                 MOVLW   D'0'
0032   0095           00075                 MOVWF   CCPR1L          ; Set Duty Cycle to 0           
0033   3004           00076                 MOVLW   B'00000100'
0034   3000           00077                 MOVLW   D'0'
0035   009B           00078                 MOVWF   CCPR2L          ; Set Duty Cycle to 0           
MPASM 03.20.02 Released          DEMO.ASM   2-20-2006  12:01:52         PAGE  3


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

0036   3004           00079                 MOVLW   B'00000100'
0037   0092           00080                 MOVWF   T2CON   
0038   303C           00081                 MOVLW   B'00111100'
0039   0097           00082                 MOVWF   CCP1CON 
003A   009D           00083                 MOVWF   CCP2CON
003B   0008           00084                 RETURN 
                      00085 
003C                  00086 Loop1ms
003C   3EFF           00087                 ADDLW   d'255'          ;Dec W
003D   1D03           00088                 BTFSS   STATUS, Z       ;Zero flag set?
003E   283C           00089                 GOTO    Loop1ms         ;       No, keep looping
003F   0008           00090                 RETURN                  ;       Yes, 1ms done
                      00091 
0040                  00092 Int
0040   00A0           00093                 movwf   WREG_TEMP       ;Save WREG
0041   0803           00094                 movf    STATUS,W        ;Store STATUS in WREG
0042   0183           00095                 clrf    STATUS          ;Select file register bank0
0043   00A1           00096                 movwf   STATUS_TEMP     ;Save STATUS value
0044   080A           00097                 movf    PCLATH,W        ;Store PCLATH in WREG
0045   00A2           00098                 movwf   PCLATH_TEMP     ;Save PCLATH value
0046   018A           00099                 clrf    PCLATH          ;Select program memory page0
0047   0804           00100                 movf    FSR,W           ;Store FSR in WREG
0048   00A3           00101                 movwf   FSR_TEMP        ;Save FSR value
                      00102 
                      00103                 Bank0                   ;Select bank0
0049   1283               M                 bcf     STATUS,RP0
004A   1303               M                 bcf     STATUS,RP1
004B   1A8C           00104                 btfsc   PIR1,RCIF       ;Test RCIF receive interrupt
004C   1683           00105                 bsf     STATUS,RP0      ;Change to bank1 if RCIF set
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
004D   1A8C           00106                 btfsc   PIE1,RCIE       ;Test if interrupt enabled if RCIF set
004E   2860           00107                 goto    GetData         ;If RCIF and RCIE set, do receive
                      00108 
                      00109                 Bank0                   ;Select bank0
004F   1283               M                 bcf     STATUS,RP0
0050   1303               M                 bcf     STATUS,RP1
0051   1A0C           00110                 btfsc   PIR1,TXIF       ;Test for TXIF transmit interrupt
0052   1683           00111                 bsf     STATUS,RP0      ;Change to bank1 if TXIF set
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
0053   1A0C           00112                 btfsc   PIE1,TXIE       ;Test if interrupt enabled if TXIF set
0054   2855           00113                 goto    EndInt          ;If TXIF and TCIE set, do transmit
                      00114 
                      00115 ;can do special error handling here - an unexpected interrupt occurred 
0055                  00116 EndInt
                      00117                 Bank0                   ;Select bank 0
0055   1283               M                 bcf     STATUS,RP0
0056   1303               M                 bcf     STATUS,RP1
0057   0823           00118                 movf    FSR_TEMP,W      ;Get saved FSR value
0058   0084           00119                 movwf   FSR             ;Restore FSR
0059   0822           00120                 movf    PCLATH_TEMP,W   ;Get saved PCLATH value
005A   008A           00121                 movwf   PCLATH          ;Restore PCLATH
005B   0821           00122                 movf    STATUS_TEMP,W   ;Get saved STATUS value
005C   0083           00123                 movwf   STATUS          ;Restore STATUS
MPASM 03.20.02 Released          DEMO.ASM   2-20-2006  12:01:52         PAGE  4


LOC  OBJECT CODE     LINE SOURCE TEXT
  VALUE

005D   0EA0           00124                 swapf   WREG_TEMP,F     ;Prepare WREG to be restored
005E   0E20           00125                 swapf   WREG_TEMP,W     ;Restore WREG without affecting STATUS
005F   0009           00126                 retfie                  ;Return from interrupt
                      00127 
                      00128 ;Get received data 
0060                  00129 GetData 
                      00130                 Bank0
0060   1283               M                 bcf     STATUS,RP0
0061   1303               M                 bcf     STATUS,RP1
0062   1898           00131                 btfsc   RCSTA,OERR      ;Test overrun error flag
0063   2873           00132                 goto    ErrOERR         ;Handle it if error
0064   1918           00133                 btfsc   RCSTA,FERR      ;Test framing error flag
0065   2876           00134                 goto    ErrFERR         ;Handle it if error
                      00135 
0066   0831           00136                 movf    DataIN1,W       ;Move last received data                
0067   00B2           00137                 movwf   DataIN2
                      00138 
0068   081A           00139                 movf    RCREG,W         ;Get received data
0069   00B1           00140                 movwf   DataIN1         ;Copy to DataIn1
                      00141 
006A   3C00           00142                 SUBLW   D'0'
006B   1D03           00143                 BTFSS   STATUS,Z        ;Test if last data was 0
006C   2872           00144                 GOTO    BlockNotComplete
                      00145 
                      00146 ;SetDutyCycle   
006D   0832           00147                 movf    DataIN2,W       ;Move last received data                
006E   00B3           00148                 movwf   DutyCycle
                      00149 
                      00150 ;VisualOutputs  
006F   0832           00151                 MOVF    DataIN2,W       
Message[305]: Using default destination of 1 (file).
Message[302]: Register in operand not in bank 0.  Ensure that bank bits are correct.
0070   05FF           00152                 ANDWF   B'11111111'
0071   0088           00153                 MOVWF   PORTD
                      00154                 
0072                  00155 BlockNotComplete
0072   2855           00156                 goto    EndInt
                      00157 ;error because OERR overrun error bit is set - clear and continue
0073                  00158 ErrOERR
0073   1218           00159                 bcf     RCSTA,CREN      ;reset the receiver logic
0074   1618           00160                 bsf     RCSTA,CREN      ;enable reception again
0075   2855           00161                 goto    EndInt
                      00162 ;error because FERR framing error bit is set - clear and continue
0076                  00163 ErrFERR 
0076   081A           00164                 movf    RCREG,W         ;discard received data that has error
0077   2855           00165                 goto    EndInt
                      00166 
                      00167 
0078   2855           00168                 GOTO    EndInt
                      00169 
                      00170 
                      00171 
                      00172                 END                     ; End source code
MPASM 03.20.02 Released          DEMO.ASM   2-20-2006  12:01:52         PAGE  5


SYMBOL TABLE
  LABEL                             VALUE 

ACKDT                             00000005
ACKEN                             00000004
ACKSTAT                           00000006
ADCON0                            0000001F
ADCON1                            0000009F
ADCS0                             00000006
ADCS1                             00000007
ADDEN                             00000003
ADFM                              00000007
ADIE                              00000006
ADIF                              00000006
ADON                              00000000
ADRESH                            0000001E
ADRESL                            0000009E
BCLIE                             00000003
BCLIF                             00000003
BF                                00000000
BRGH                              00000002
Bank0                             
Bank1                             
Bank2                             
Bank3                             
BlockNotComplete                  00000072
C                                 00000000
C1INV                             00000004
C1OUT                             00000006
C2INV                             00000005
C2OUT                             00000007
CCP1CON                           00000017
CCP1IE                            00000002
CCP1IF                            00000002
CCP1M0                            00000000
CCP1M1                            00000001
CCP1M2                            00000002
CCP1M3                            00000003
CCP1X                             00000005
CCP1Y                             00000004
CCP2CON                           0000001D
CCP2IE                            00000000
CCP2IF                            00000000
CCP2M0                            00000000
CCP2M1                            00000001
CCP2M2                            00000002
CCP2M3                            00000003
CCP2X                             00000005
CCP2Y                             00000004
CCPR1H                            00000016
CCPR1L                            00000015
CCPR2H                            0000001C
CCPR2L                            0000001B
CHS0                              00000003
CHS1                              00000004
CHS2                              00000005
MPASM 03.20.02 Released          DEMO.ASM   2-20-2006  12:01:52         PAGE  6


SYMBOL TABLE
  LABEL                             VALUE 

CIS                               00000003
CKE                               00000006
CKP                               00000004
CM0                               00000000
CM1                               00000001
CM2                               00000002
CMCON                             0000009C
CMIE                              00000006
CMIF                              00000006
CREN                              00000004
CSRC                              00000007
CVR0                              00000000
CVR1                              00000001
CVR2                              00000002
CVR3                              00000003
CVRCON                            0000009D
CVREN                             00000007
CVROE                             00000006
CVRR                              00000005
D                                 00000005
DATA_ADDRESS                      00000005
DC                                00000001
D_A                               00000005
DataIN1                           00000031
DataIN2                           00000032
DutyCycle                         00000033
EEADR                             0000010D
EEADRH                            0000010F
EECON1                            0000018C
EECON2                            0000018D
EEDATA                            0000010C
EEDATH                            0000010E
EEIE                              00000004
EEIF                              00000004
EEPGD                             00000007
EndInt                            00000055
ErrFERR                           00000076
ErrOERR                           00000073
F                                 00000001
FERR                              00000002
FSR                               00000004
FSR_TEMP                          00000023
GCEN                              00000007
GIE                               00000007
GO                                00000002
GO_DONE                           00000002
GetData                           00000060
I2C_DATA                          00000005
I2C_READ                          00000002
I2C_START                         00000003
I2C_STOP                          00000004
IBF                               00000007
IBOV                              00000005
MPASM 03.20.02 Released          DEMO.ASM   2-20-2006  12:01:52         PAGE  7


SYMBOL TABLE
  LABEL                             VALUE 

INDF                              00000000
INTCON                            0000000B
INTE                              00000004
INTEDG                            00000006
INTF                              00000001
IRP                               00000007
Int                               00000040
Loop                              00000014
Loop1ms                           0000003C
Main                              00000005
NOT_A                             00000005
NOT_ADDRESS                       00000005
NOT_BO                            00000000
NOT_BOR                           00000000
NOT_DONE                          00000002
NOT_PD                            00000003
NOT_POR                           00000001
NOT_RBPU                          00000007
NOT_RC8                           00000006
NOT_T1SYNC                        00000002
NOT_TO                            00000004
NOT_TX8                           00000006
NOT_W                             00000002
NOT_WRITE                         00000002
OBF                               00000006
OERR                              00000001
OPTION_REG                        00000081
P                                 00000004
PCFG0                             00000000
PCFG1                             00000001
PCFG2                             00000002
PCFG3                             00000003
PCL                               00000002
PCLATH                            0000000A
PCLATH_TEMP                       00000022
PCON                              0000008E
PEIE                              00000006
PEN                               00000002
PIE1                              0000008C
PIE2                              0000008D
PIR1                              0000000C
PIR2                              0000000D
PORTA                             00000005
PORTB                             00000006
PORTC                             00000007
PORTD                             00000008
PORTE                             00000009
PR2                               00000092
PS0                               00000000
PS1                               00000001
PS2                               00000002
PSA                               00000003
PSPIE                             00000007
MPASM 03.20.02 Released          DEMO.ASM   2-20-2006  12:01:52         PAGE  8


SYMBOL TABLE
  LABEL                             VALUE 

PSPIF                             00000007
PSPMODE                           00000004
R                                 00000002
RBIE                              00000003
RBIF                              00000000
RC8_9                             00000006
RC9                               00000006
RCD8                              00000000
RCEN                              00000003
RCIE                              00000005
RCIF                              00000005
RCREG                             0000001A
RCSTA                             00000018
RD                                00000000
READ_WRITE                        00000002
RP0                               00000005
RP1                               00000006
RSEN                              00000001
RX9                               00000006
RX9D                              00000000
R_W                               00000002
Ram                               00000020
S                                 00000003
SEN                               00000000
SMP                               00000007
SPBRG                             00000099
SPEN                              00000007
SREN                              00000005
SSPADD                            00000093
SSPBUF                            00000013
SSPCON                            00000014
SSPCON2                           00000091
SSPEN                             00000005
SSPIE                             00000003
SSPIF                             00000003
SSPM0                             00000000
SSPM1                             00000001
SSPM2                             00000002
SSPM3                             00000003
SSPOV                             00000006
SSPSTAT                           00000094
STATUS                            00000003
STATUS_TEMP                       00000021
SYNC                              00000004
SetupPWM                          0000002D
SetupSerial                       00000017
T0CS                              00000005
T0IE                              00000005
T0IF                              00000002
T0SE                              00000004
T1CKPS0                           00000004
T1CKPS1                           00000005
T1CON                             00000010
MPASM 03.20.02 Released          DEMO.ASM   2-20-2006  12:01:52         PAGE  9


SYMBOL TABLE
  LABEL                             VALUE 

T1INSYNC                          00000002
T1OSCEN                           00000003
T1SYNC                            00000002
T2CKPS0                           00000000
T2CKPS1                           00000001
T2CON                             00000012
TMR0                              00000001
TMR1CS                            00000001
TMR1H                             0000000F
TMR1IE                            00000000
TMR1IF                            00000000
TMR1L                             0000000E
TMR1ON                            00000000
TMR2                              00000011
TMR2IE                            00000001
TMR2IF                            00000001
TMR2ON                            00000002
TOUTPS0                           00000003
TOUTPS1                           00000004
TOUTPS2                           00000005
TOUTPS3                           00000006
TRISA                             00000085
TRISB                             00000086
TRISC                             00000087
TRISD                             00000088
TRISE                             00000089
TRISE0                            00000000
TRISE1                            00000001
TRISE2                            00000002
TRMT                              00000001
TX8_9                             00000006
TX9                               00000006
TX9D                              00000000
TXD8                              00000000
TXEN                              00000005
TXIE                              00000004
TXIF                              00000004
TXREG                             00000019
TXSTA                             00000098
Timer_local                       00000030
UA                                00000001
W                                 00000000
WCOL                              00000007
WR                                00000001
WREG_TEMP                         00000020
WREN                              00000002
WRERR                             00000003
Z                                 00000002
_BODEN_OFF                        00003FBF
_BODEN_ON                         00003FFF
_CPD_OFF                          00003FFF
_CPD_ON                           00003EFF
_CP_ALL                           00001FFF
MPASM 03.20.02 Released          DEMO.ASM   2-20-2006  12:01:52         PAGE 10


SYMBOL TABLE
  LABEL                             VALUE 

_CP_OFF                           00003FFF
_DEBUG_OFF                        00003FFF
_DEBUG_ON                         000037FF
_HS_OSC                           00003FFE
_LP_OSC                           00003FFC
_LVP_OFF                          00003F7F
_LVP_ON                           00003FFF
_PWRTE_OFF                        00003FFF
_PWRTE_ON                         00003FF7
_RC_OSC                           00003FFF
_WDT_OFF                          00003FFB
_WDT_ON                           00003FFF
_WRT_1FOURTH                      00003BFF
_WRT_256                          00003DFF
_WRT_HALF                         000039FF
_WRT_OFF                          00003FFF
_XT_OSC                           00003FFD
__16F877A                         00000001


MEMORY USAGE MAP ('X' = Used,  '-' = Unused)

0000 : XXX-XXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX
0040 : XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXX XXXXXXXXX-------
2000 : -------X-------- ---------------- ---------------- ----------------

All other memory blocks unused.

Program Memory Words Used:   120
Program Memory Words Free:  8072


Errors   :     0
Warnings :     0 reported,     0 suppressed
Messages :    15 reported,     0 suppressed

